<?php
/**
 * Img.php
 * Fri Aug 31 10:59:24 JST 2007
 * @auther : qqinxl
 * LICENSE 
 *
 * @copyright  Copyright (c) lin-international
 */
class Htmlhelper_Img {
	const IMG_SUCCESS = 'success';
	const IMG_OK = 'ok';
	const IMG_FAIL = 'fail';
	const IMG_WARNING = 'warning';
	const IMG_WRONG = 'wrong';
	const IMG_ERROR = 'error';
	const IMG_LOADING = 'loading';
	const IMG_HOME = 'home';
	const IMG_FRIEND = 'friend';
	const IMG_COMMENTS = 'comment';
	const IMG_CALENDAR = 'calendar';
	
	const IMG_COUNTRY_CN = 'cn';
	const IMG_COUNTRY_JP = 'jp';
	const IMG_COUNTRY_EN = 'us';
	
	const IMG_ARROW_UP = 'up';
	const IMG_ARROW_DOWN = 'down';
	
	static public function showHintImg($baseUrl, $imgtype, $text = null) {
		$_src = $baseUrl . '/public/images/icons/';
		switch ( $imgtype) {
			case self::IMG_OK :
				$_imgfile = 'ok.gif';
			break;
			case self::IMG_SUCCESS :
				$_imgfile = 'success.gif';
			break;
			case self::IMG_FAIL :
				$_imgfile = 'fail.gif';
			break;
			case self::IMG_WARNING :
				$_imgfile = 'warning.gif';
			break;
			case self::IMG_WRONG :
				$_imgfile = 'wrong.gif';
			break;
			case self::IMG_ERROR :
				$_imgfile = 'error.gif';
			break;
			case self::IMG_LOADING :
				$_imgfile = 'loading.gif';
			break;
			case self::IMG_HOME :
				$_imgfile = 'home.gif';
			break;
			case self::IMG_FRIEND :
				$_imgfile = 'friend.gif';
			break;
			case self::IMG_COMMENTS :
				$_imgfile = 'comments.gif';
			break;
			case self::IMG_CALENDAR :
				$_imgfile = 'calendar.gif';
			break;	
			case self::IMG_COUNTRY_CN :
				$_imgfile = 'country/cn.gif';
			break;	
			case self::IMG_COUNTRY_JP :
				$_imgfile = 'country/jp.gif';
			break;	
			case self::IMG_COUNTRY_EN :
				$_imgfile = 'country/us.gif';
			break;	
			case self::IMG_ARROW_DOWN :
				$_imgfile = 'down.gif';
			break;	
			case self::IMG_ARROW_UP:
				$_imgfile = 'up.gif';
			break;			
			default :
				$_imgfile = 'comments.gif';
			break;
		}
		$_src .= $_imgfile;
		$html = "<img src='" . $_src . "' border='0'/>";
		if (! empty ( $text )) {
			$html .= " " . $text . "";
		}
		return $html;
	}
	static public function showImage($fileName,$file_type = 'image/jpg'){
		try{		
			if(file_exists($fileName)){				
				$handle = fopen ($fileName, "rb");
				if(!$handle){
					throw new Exception('Cannot open the file.');
				}
				$tt = null;
				if ($handle){
					while(!feof($handle) && connection_status() == 0){
						set_time_limit(0);
						if(empty($tt)){
							$tt = fread($handle,1024*8);
						}else{
							$tt .= fread($handle,1024*8);
						}
					}
					fclose($handle);
				}				
				header("Content-type: ".$file_type);											
				header("Cache-Control: no-cache, must-revalidate");
				echo $tt;			
				exit;
			}else{
				throw new Exception('No file.'.$fileName);
			}
		}catch(Exception $e){
			throw $e;
		}
	}
}